package wymiana.service;

import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wymiana.dao.SchoolDao;
import wymiana.domain.School;

/**
 * 
 * @author Rafal Magdon
 * @version 1.0
 * 
 *          Description:
 * 
 */
@Service("schoolService")
@Transactional
public class SchoolService {

	@Autowired
	private SchoolDao schoolDao;

	public void create(School person) {
		schoolDao.save(person);

	}

	public List<School> getAllSchools() {
		return schoolDao.getAll();
	}

	public School getSchool(int p_id) {
		School s = schoolDao.getSchoolById(p_id);
		Hibernate.initialize(s.getDepartments());
		return s;
	}

	public void updateSchool(School p) {
		schoolDao.merge(p);
	}

	public void deleteSchoolByID(int p_id) {
		School s = schoolDao.getSchoolById(p_id);
		schoolDao.delete(s);
	}

	public void deleteSchool(School s) {
		schoolDao.delete(s);
	}

}
